home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / MotifScrollBarUI.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  146 lines

  1. /*
  2.  * @(#)MotifScrollBarUI.java    1.4 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.plaf.motif;
  21.  
  22. import com.sun.java.swing.*;
  23. import com.sun.java.swing.event.*;
  24. import com.sun.java.swing.plaf.*;
  25. import com.sun.java.swing.border.*;
  26. import com.sun.java.swing.plaf.basic.BasicScrollBarUI;
  27. import com.sun.java.swing.plaf.basic.BasicGraphicsUtils;
  28.  
  29. import java.awt.Dimension;
  30. import java.awt.Insets;
  31. import java.awt.Rectangle;
  32. import java.awt.Graphics;
  33. import java.awt.Color;
  34.  
  35.  
  36. /**
  37.  * Implementation of ScrollBarUI for the Motif Look and Feel
  38.  * <p>
  39.  * Warning: serialized objects of this class will not be compatible with
  40.  * future swing releases.  The current serialization support is appropriate
  41.  * for short term storage or RMI between Swing1.0 applications.  It will
  42.  * not be possible to load serialized Swing1.0 objects with future releases
  43.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  44.  * baseline for the serialized form of Swing objects.
  45.  *
  46.  * @version 1.4 02/02/98
  47.  * @author Rich Schiavi
  48.  * @author Hans Muller
  49.  */
  50. public class MotifScrollBarUI extends BasicScrollBarUI 
  51. {
  52.     /* The following fields are returned by the corresponding
  53.      * get methods rather than heap allocating new Dimension 
  54.      * objects.
  55.      */
  56.     private static final Dimension minimumThumbSize = new Dimension(8, 8);
  57.     private static final Dimension maximumThumbSize = new Dimension(4096, 4096);
  58.  
  59.  
  60.     /* The following static fields are lazily computed by 
  61.      * configureScrollBarColors() and are shared by all MotifScrollBarUI 
  62.      * instances. 
  63.      */
  64.  
  65.     private static Color thumbHighlightColor;
  66.     private static Color thumbShadowColor;
  67.     private static Color thumbColor;
  68.     private static Color trackColor;
  69.     private static boolean scrollBarColorsInitialized = false;
  70.  
  71.  
  72.     public static ComponentUI createUI(JComponent c) {
  73.     return new MotifScrollBarUI();
  74.     }
  75.  
  76.  
  77.     protected void configureScrollBarColors() {
  78.     if (!scrollBarColorsInitialized) {
  79.         thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
  80.         thumbShadowColor = UIManager.getColor("ScrollBar.thumbLightShadow");
  81.         thumbColor = UIManager.getColor("ScrollBar.thumb");
  82.         trackColor = UIManager.getColor("ScrollBar.track");
  83.         scrollBarColorsInitialized = true;
  84.     }
  85.     }
  86.  
  87.  
  88.     public Dimension getPreferredSize(JComponent c) {
  89.     Insets insets = c.getInsets();
  90.     int dx = insets.left + insets.right;
  91.     int dy = insets.top + insets.bottom;
  92.     return (scrollbar.getOrientation() == JScrollBar.VERTICAL)
  93.         ? new Dimension(dx + 11, dy + 33)
  94.         : new Dimension(dx + 33, dy + 11);
  95.     }
  96.  
  97.  
  98.     protected Dimension getMinimumThumbSize() { 
  99.     return minimumThumbSize;
  100.     }
  101.  
  102.     protected Dimension getMaximumThumbSize()    { 
  103.     return maximumThumbSize;
  104.     }
  105.  
  106.  
  107.     protected JButton createDecreaseButton(int orientation) {
  108.     return new MotifScrollBarButton(orientation);
  109.     } 
  110.  
  111.     protected JButton createIncreaseButton(int orientation) {
  112.     return new MotifScrollBarButton(orientation);
  113.     }
  114.   
  115.  
  116.     public void paintTrack(Graphics g, JComponent c, Rectangle trackBounds)  {        
  117.         g.setColor(trackColor);
  118.         g.fillRect(trackBounds.x, trackBounds.y, trackBounds.width, trackBounds.height);
  119.     }
  120.  
  121.  
  122.     public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)  
  123.     {        
  124.     if(thumbBounds.isEmpty() || !scrollbar.isEnabled())    {
  125.         return;
  126.     }
  127.  
  128.     int w = thumbBounds.width;
  129.     int h = thumbBounds.height;        
  130.       
  131.     g.translate(thumbBounds.x, thumbBounds.y);
  132.     g.setColor(thumbColor);
  133.     g.fillRect(0, 0, w-1, h-1);
  134.       
  135.     g.setColor(thumbHighlightColor);
  136.     g.drawLine(0, 0, 0, h-1);
  137.     g.drawLine(1, 0, w-1, 0);
  138.       
  139.     g.setColor(thumbShadowColor);
  140.     g.drawLine(1, h-1, w-1, h-1);
  141.     g.drawLine(w-1, 1, w-1, h-2);
  142.  
  143.     g.translate(-thumbBounds.x, -thumbBounds.y);
  144.     }
  145. }
  146.